<template>
    <el-dialog title="修改学科" :visible.sync="dialogFormVisible">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="学科名称" prop="subjectName">
                <el-input v-model="ruleForm.subjectName"></el-input>
            </el-form-item>
            <el-form-item label="是否显示" prop="isFrontDisplay">
                <el-switch v-model="ruleForm.isFrontDisplay" :active-value="1" :inactive-value="0"></el-switch>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="primary()">确认</el-button>
                <el-button @click="resetForm">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script>
import { update } from '@/api/hmmm/subjects.js'
export default {
  data () {
    return {
      dialogFormVisible: false,
      ruleForm: {
        subjectName: '',
        isFrontDisplay: 1,
        id: ''
      },
      rules: {
        subjectName: [
          { required: true, message: '请输入角色名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async openDialog (row) {
      console.log(row)
      console.log(row.subjectName)
      this.ruleForm.subjectName = row.subjectName
      this.ruleForm.id = row.id
      this.dialogFormVisible = true
    },
    async resetForm () {
      this.$refs.ruleForm.resetFields()

      this.dialogFormVisible = false
    },
    async primary () {
      const res = await update({ id: this.ruleForm.id, subjectName: this.ruleForm.subjectName, isFrontDisplay: this.ruleForm.isFrontDisplay })
      console.log(res)
      this.$emit('UPDATE_ROLE_SUCCESS')
      this.resetForm()
    }

  }
}
</script>
